﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;
using Entities;
using System.Data;
namespace BusinessLogicLayer
{
    public class KhachHangBO
    {
        private KhachHangDAL dal;
        public KhachHangBO()
        {
            dal = new KhachHangDAL();
        }

        public KhachHang layThongTinKhachHang(int maKhachHang)
        {
            KhachHang Kh = new KhachHang();
            DataTable table = new DataTable();
            table = dal.layThongTinKhachHang(maKhachHang);
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows) 
                {
                    Kh.HoTenKhachHang = (String)row["KH_HoTenKhachHang"];
                    Kh.TienNo = (float)(double)row["KH_TienNo"];
                    Kh.MaKhachHang = (int)row["KH_MAKHACHHANG"];
                    Kh.DiaChi = (String)row["KH_DiaChi"];
                    Kh.DienThoai = (String)row["KH_DIENTHOAI"];
                    Kh.Email = (String)row["KH_EMAIL"];
                }
            }
            return Kh;
        }
        public DataTable layDanhSachKhachHang()
        {
            DataTable dt = null;
            try
            {
                dt = dal.layDanhSachKhachHang();
                return dt;
            }
            catch (Exception)
            {
                return dt;
                throw;
            }

        }
        public int InsertKhachHang(KhachHang kh)
        {
            int dt = 0;
            try
            {
                dt = dal.InsertKhachHang(kh);
                return dt;
            }
            catch (Exception)
            {
                return dt;
                throw;
            }

        }
        public int DeleteKhachHang(string maKhachHang)
        {
            int dt = 0;
            try
            {
                dt = dal.DeleteKhachHang(maKhachHang);
                return dt;
            }
            catch (Exception)
            {
                return dt;
                throw;
            }

        }
        public int UpdateKhachHang(KhachHang kh)
        {
            int dt = 0;
            try
            {
                dt = dal.UpdateKhachHang(kh);
                return dt;
            }
            catch (Exception)
            {
                return dt;
                throw;
            }

        }
    }
}
